var windowName = "shopAuth";
var Page,HeadPics;
apiready = function(){
    HeadPics = new PicUp();
    onWindowShow(function () {
        console.log(windowName + " show")
    })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        name:""
        ,code:""
        ,pic:""
        ,log:[]
    },{
        //页面方法
        "init":function () {
            this.log = getLocData("shopAuth");
            apiGet("/api/shopAuths", {}, function (res , code) {
                logJson(res,"/api/shopAuths_Get")
                if (code == 200) {
                    Page.log = res.data;
                    // showToast(res.message)
                    setLocData("shopAuth",res.data)
                }else {
                    showToast("系统繁忙")
                }
            });
            HeadPics.setCbFunc(function (pics) {
                logJson(pics,"pics_selectHeadPic")
                // _this.pics = ProductPics.getViewData()
                if (HeadPics.getData()) {
                    Page.pic = HeadPics.getData()[0];
                }

            })
        }
        ,selectHeadPic:function () {
            var _this = this;
            HeadPics.uploadedPath = [];
            HeadPics.chooseSrc(1)
        }
        , submit: function () {
            if (!isTrue(this.name)) {showToast("名称不能为空");return}
            if (!isTrue(this.code)) {showToast("营业执照注册号不能为空");return}
            if (!isTrue(this.pic)) {showToast("请上传营业执照");return}
            var data = {
                name:this.name,
                code:this.code,
                pic:this.pic
            }
            var _this = this;
            apiPost("/api/shopAuths", data, function (res , code) {
                logJson(res,"/api/shopAuths")
                if (code == 200) {
                    _this.init();
                    showToast(res.message)
                }else {
                    showToast("系统繁忙")
                }
            });
        }
    })
    Page.init()
}
